package cn.deschen.search.mysql.handlers;

import cn.deschen.common.utils.SpringUtil;
import cn.deschen.search.constants.TableInfo;
import cn.deschen.search.mysql.handlers.impl.*;

/**
 * @Author hanbin_chen
 * @Description binlog日志记录数据处理工厂
 * @DateTime 2021/6/11
 * @Version V1.0.0
 */
public class BinlogRowDataHandlerFactory {

    /**
     * 根据数据表名获取对应处理器
     *
     * @param datesource
     * @param tableName
     * @return
     */
    public static BinlogRowDataHandler getHandler(String datesource, String tableName) {
        BinlogRowDataHandler handler = null;
        switch (TableInfo.get(datesource, tableName)) {
            case NAME_AD_PLAN:
                handler = SpringUtil.getBean(AdPlanHandler.class);
                break;
            case NAME_AD_CREATIVE:
                handler = SpringUtil.getBean(AdCreativeHandler.class);
                break;
            case NAME_AD_UNIT:
                handler = SpringUtil.getBean(AdUnitHandler.class);
                break;
            case NAME_AD_TAG:
                handler = SpringUtil.getBean(AdTagHandler.class);
                break;
            case NAME_AD_KEYWORD:
                handler = SpringUtil.getBean(AdKeywordHandler.class);
                break;
            case NAME_AD_REGION:
                handler = SpringUtil.getBean(AdRegionHandler.class);
                break;
            case NAME_AD_UNIT_ELE:
                handler = SpringUtil.getBean(AdUnitEleHandler.class);
                break;
        }
        return handler;
    }
}
